//
//  TimeFlagView.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2024/8/5.
//  Copyright © 2024 zwb. All rights reserved.
//
 
import UIKit
import Kingfisher
var tenderBlue = "5793DF"
 
var tenderGreen = "579F2B"
class ZTBComCell: UITableViewCell {
    

    lazy var lab1: UILabel = {
        let v = UILabel()
        v.numberOfLines = 2
        v.font = UIFont.boldSystemFont(ofSize: 17)
        
        return v
    }()

    lazy var labCity: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 13)
        v.textColor = .lightGray
        return v
    }()
    lazy var btnDtradeType: DtradeTypeUIButton = {
        let v = DtradeTypeUIButton()
        v.isHidden = true
        v.layer.cornerRadius = 14
        v.layer.masksToBounds = true
        v.backgroundColor = Theme.primaryColor()
        v.setTitleColor(.white, for: .normal)
        v.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        return v
    }()
    
    
    lazy var lab4: UILabel = {
        
        let lab4 = UILabel()
        lab4.font = UIFont.systemFont(ofSize: 13)
        lab4.textColor = #colorLiteral(red: 0.9254901961, green: 0.3215686275, blue: 0.06274509804, alpha: 1)
        return lab4
    }()
    lazy var chujiaLab: UILabel = {
        let  chujiaLab = UILabel()
        chujiaLab.textColor = .lightGray
        chujiaLab.font = UIFont.systemFont(ofSize: 14)
        chujiaLab.numberOfLines = 2
        return chujiaLab
    }()
    
    lazy  var imageV:UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFit
        imageV.layer.cornerRadius = 8
        imageV.layer.masksToBounds = true
        return imageV
    }()
    lazy  var chengjiaoImg:UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFit
        imageV.image = UIImage(named: "tenderchengjiao")
        imageV.isHidden = true
        return imageV
    }()
    
   
    var viewJPClosure:((UIButton,String)->())?
    lazy var titleAttributes:[NSAttributedString.Key : NSObject] = {
        let paraph = NSMutableParagraphStyle()
        //将行间距设置为
        paraph.lineSpacing = 9
        //样式属性集合
        let titleAttributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 17),
                               NSAttributedString.Key.paragraphStyle: paraph]
        return titleAttributes
    }()
    lazy var lab3Attributes:[NSAttributedString.Key : NSObject] = {
        
        
        let paraph2 = NSMutableParagraphStyle()
        //将行间距设置为
        paraph2.lineSpacing = 6
        //样式属性集合
        let  lab3Attributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14),
                               NSAttributedString.Key.paragraphStyle: paraph2]
        return lab3Attributes
    }()
    let helper = ZyaTenderHelper()
    
    
    lazy var bottomStatusBg:BottomStatusV = {
        let v = BottomStatusV()
        return v
    }()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
        
        self.contentView.addSubview(lab1)
        
        
        self.contentView.addSubview(labCity)
        
        
        
        
        self.contentView.addSubview(chujiaLab)
        
        self.contentView.addSubview(lab4)
        
      
        
        self.contentView.addSubview(imageV)
        imageV.addSubview(btnDtradeType)
        
        self.contentView.addSubview(chengjiaoImg)

        self.contentView.addSubview(bottomStatusBg)
  
        
    }
    func judgeAddtime(_ one:BaseFormModel) {
        if one.zIfOvertime.unwrap == "1" {
            var tstr =  "加时0次"
            if intTran(one.zOvertimedNum) > 0 {
                tstr = "加时\(one.zOvertimedNum.unwrap)次"
            }
            bottomStatusBg.addtimeLab.isHidden = false
            bottomStatusBg.addtimeLab.text = tstr
       
        } else {
            bottomStatusBg.addtimeLab.isHidden = true
        }
   
    }
    
    
    func makeConstrainsts() {
        
        
        
        imageV.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView).offset(6)
            make.centerY.equalTo(self.contentView)
            make.width.height.equalTo(70)
           
            
        }
        btnDtradeType.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(-10)

             make.width.equalTo(53)
            make.height.equalTo(32)

        }
        chengjiaoImg.snp.makeConstraints { (make) in
            make.left.top.equalTo(self.contentView)
            make.width.height.equalTo(60)
        }
        lab1.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView).offset(12)
            make.left.equalTo(imageV.snp.right).offset(8)
            make.right.equalTo(self.contentView).offset(-10)
         
            //                make.bottom.equalTo(self).offset(-100)
        }
        labCity.snp.makeConstraints { make in
            make.left.equalTo(lab1)
            make.top.equalTo(lab1.snp.bottom).offset(3)
        }
        
        chujiaLab.snp.makeConstraints { (make) in
            make.centerY.equalTo(bottomStatusBg.statusBtn)
            make.right.equalTo(self.contentView).offset(-6)
        }
        
        
        lab4.snp.makeConstraints { (make) in
            make.right.equalTo(bottomStatusBg)
            make.centerY.equalTo(labCity)
            
        }
        
        bottomStatusBg.snp.makeConstraints { (make) in
            
            make.left.equalTo(lab1)
            make.right.equalTo(self.contentView).offset(-6)
            make.height.equalTo(22)
            make.top.equalTo(labCity.snp.bottom).offset(6)
            make.bottom.equalToSuperview().offset(-12)
        }
    
        
    }

    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}

 
 

class BottomStatusV:UIView {
    lazy var statusBtn: ZyaStatusButton = {
        let v = ZyaStatusButton()
     
        return v
    }()
    lazy var lab2: TimeRemainLabel = {
        let v = TimeRemainLabel()
        v.numberOfLines = 0
        v.font = UIFont.systemFont(ofSize: 12)
        v.textColor = .darkGray
        v.textAlignment = .right
        return v
    }()
    var addtimeLab:UILabel = {
        var v = UILabel()
        v.font = UIFont.systemFont(ofSize: 12)
        v.textColor = #colorLiteral(red: 0.9254901961, green: 0.3215686275, blue: 0.06274509804, alpha: 1)
        v.text = "加时0次"
        v.textAlignment = .right
        return v
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.layer.masksToBounds = true
        self.backgroundColor = UIColor(kshex: "f3f3f3")
        self.addSubview(statusBtn)
        self.addSubview(lab2)
        self.addSubview(addtimeLab)
        statusBtn.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(-10)
            make.width.equalTo(55)
        }
 
        lab2.snp.makeConstraints { (make) in
            make.left.equalTo(statusBtn.snp.right).offset(6)
            make.right.equalTo(addtimeLab.snp.left).offset(-2).priority(666)

             make.centerY.equalToSuperview()
        }
        addtimeLab.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-1)
             make.centerY.equalToSuperview()
        }
        
     }
    
    required  init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class DtradeTypeUIButton:UIButton {
    override func layoutSubviews() {
        super.layoutSubviews()
        self.titleLabel?.frame = CGRect(x: 8, y: 10, width: self.ks_width - 10, height: self.ks_height - 10)
    }
}
